/*
 * Perion Gachapon
 * @author: DejaVu
*/

void npc(Player @player, NPC @npc) {
	int state = npc.getState();
	const int [] items = {2060001, 2061001, 2000005, 4020004, 4010000, 4020003, 4010002, 2000002, 2040805, 2044702, 2043302, 2041020, 2040502, 2043102, 2044302, 1050018, 1332026, 1032032, 1032032, 1452004, 1040070, 1041066, 1040073, 1041068, 1041008, 1041063, 1002137, 1061080, 1002064, 1002145, 1382007, 1040019, 1002073, 1040035, 1040048, 1332008, 1060043, 1040058, 1472007, 1041044, 1060032, 1002056, 1312001, 1050005, 1060028, 1040012, 1061015, 1002086, 1002055, 1082036, 1002011, 1061087, 1002056, 1002058, 1412004, 1041028, 1082150, 1082148, 1082146, 1082145, 2340000, 1302021, 1432013, 1002359, 1002393};
	int selection = npc.getSelected();
	if(state == 0){
		if(player.getItemAmount(5220000) > 0){
			npc.addText("You may use Gachapon. Would you like to use your Gachapon ticket?");
			npc.sendYesNo();
		} else {
			npc.addText("Welcome to the Perion Gachapon. How may I help you?\r\n\r\n#L0#What is Gachapon?#l\r\n#L1#Where can you buy Gachapon tickets?#l");
			npc.sendSimple();
		}
	}
	else if(state == 1){
		if(player.getItemAmount(5220000) > 0){
			if(npc.getSelected() == YES){
				const int amt = 65;
				int prize = random(amt);
				player.giveItem(5220000, -1);
				player.giveItem(items[prize], 1);
				npc.end();
			} else {
				npc.end();
			}
		} else {
			if(selection == 0){
				npc.addText("Play Gachapon to earn rare scrolls, equipment, chairs, mastery books, and other cool items! All you need is a #bGachapon Ticket#k to be the winner of a random mix of items.");
				npc.sendOK();
				npc.end();
			}
			else if(selection == 1){
				npc.addText("Gachapon Tickets are available in the #rCash Shop#k and can be purchased using NX or Maple Points. Click on the red SHOP at the lower right hand corner of the screen to visit the #rCash Shop #kwhere you can purchase tickets.");
				npc.sendOK();
				npc.end();
			} else {
				npc.end();
			}
		}
	} else {
		npc.end();
	}
}